<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03.闭包.html</title>
</head>

<body>
    <button id="btn1">按钮20</button>
    <button id="btn2">按钮40</button>
    <button id="btn3">按钮60</button>

    <script>
        function changeSize(size) {
            return function () {
                this.style.fontSize = size + "px";
            }
        }
        btn1.onclick = changeSize(20)
        btn2.onclick = changeSize(40)
        btn3.onclick = changeSize(60)
        function fun() {
            var a = 10;
            function fun2() {
                // debugger;
                console.log(a);
            }
            fun2()
        }
        fun();
        console.log("========================");
        // 获取同一个随机数
        function getRandom() {
            const num = Math.floor(Math.random() * 10 + 1)
            return () => num
        }
        const myfun = getRandom()
        console.log(myfun());
        console.log(myfun());
        console.log(myfun());
        console.log("========================");
        // 获取 n+a n+b n+c .....
        function getSum(n) {
            return (m) => n + m;
        }
        const fn = getSum(10)
        console.log(fn(100));
        console.log(fn(1000));
        console.log(fn(10000));
        console.log("=======================");
        const arr = [10, 20, 40, 50, 60, 70, 80, 100, 120]
        // 每次都要写 麻烦 
        console.log(arr.filter(item => item >= 10 && item <= 70));
        console.log(arr.filter(item => item >= 40 && item <= 100));
        console.log(arr.filter(between(10, 70)));
        console.log(arr.filter(between(40, 100)));
        function between(m, n) {
            return item => item >= m && item <= n
        }
    </script>

</body>

</html>